/**
 * 全局扩展
 */

export default{
    install(Vue){
        Vue.prototype.$myName = "zhagngsan";
        //查找元素在数组中的位置
        Array.prototype.indexOf = function(val) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == val) return i;
            }
            return -1;
        }
        //数组去重复
        Array.prototype.unique = function() {
            return Array.from(new Set(this));
        }
        //时间戳转换
        Number.prototype.toDate = function() {
            let _this = this;
            let date = new Date(_this );
            let Y,M,D,h,m,s;
            Y = date.getFullYear() + '-';
            M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            D = date.getDate() + ' ';
            h = date.getHours() + ':';
            m = date.getMinutes() + ':';
            s = date.getSeconds();
            return Y+M+D+h+m+s;
        }
        String.prototype.htmlToText = function(num){
            let _this = this,result='',text = '';
            _this+='';
            if(!_this) return false;
            text =  _this.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' ');
            text = text.replace(/&nbsp;/g,'')
            result = text.slice(0, num);
            if (text.length > num) result += '...';
            return result;
        }
    }
}
